﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Eis51.CampanyCMS.Model.BaseInfoMng;
using Eis51.CampanyCMS.Business.BaseInfoMng;
using Eis51.CampanyCMS.Business;
using System.Data;
using Eis51.CampanyCMS.Business.OnlineService;
using Eis51.CampanyCMS.Model.OnlineService;
using Eis51.CampanyCMS.Model;
using Eis51.Web.Admin;

namespace Eis51.CampanyCMS.UI.Admin.OnlineService
{
    public partial class edit : BasePage
    {
        

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitData();
            }
        }

        private void InitData()
        {
            ddlChatTools.DataSource = BaseChatToolsBLL.GetInstance().Select();
            ddlChatTools.DataTextField = "ChatToolName";
            ddlChatTools.DataValueField = "ChatToolCODE";
            ddlChatTools.DataBind();
        } 


        protected void ddlChatTyle_SelectedIndexChanged(object sender, EventArgs e)
        {
            ddlStyle.Items.Clear();
            DataTable lst = BaseChatToolsStyleBLL.GetInstance().GetListByChatToolsCode(ddlChatTools.SelectedValue);
            foreach (DataRow dr in lst.Rows)
            {
                ListItem li = new ListItem();
                li.Text = dr["Chat_Style_Name"].ToString();
                li.Value = dr["Chat_Style_Code"].ToString();
                if (dr["Chat_Style_Src"].ToString() != string.Empty)
                {
                    li.Attributes.Add("title", dr["Chat_Style_Src"].ToString());
                }                
                ddlStyle.Items.Add(li);
            }
            
            
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            BaseMyChatTools mc = new BaseMyChatTools();
            string template = BaseChatToolsBLL.GetInstance().GetByChatToolsCode(ddlChatTools.SelectedValue).ChatToolTemplate;
            mc.ChatNum = txtChatNum.Text;
            mc.ChatStyle = ddlStyle.SelectedValue;
            mc.ChatToolCode = ddlChatTools.SelectedValue;
            mc.ChatToolName = ddlChatTools.SelectedItem.Text;
            mc.ShowName = txtChatShowName.Text;
            mc.Createby = AppContext.CurrentAdministrator.UserName;
            mc.LinkContent = template.Replace("{CHAT_NUM}", mc.ChatNum).Replace("{CHAT_STYLE}", mc.ChatStyle).Replace("{CHAT_NAME}", mc.ShowName);
            BaseMyChatToolsBLL.GetInstance().Insert(mc);
            btnReturn_Click(null, null);
        }

        protected void btnReturn_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/admin/OnlineServicelist/list1.aspx");
        }
    }
}
